package com.aim.analysis.records;

import com.aim.analysis.artifact.Strategy;
import com.aim.util.extractors.ValueExtractor;

/**
 * User: Avraham Shvartzon
 * Date: 8/16/14
 */
public abstract class HitValueExtractor<V> extends ValueExtractor<Hit, V> {

    public HitValueExtractor(String name) {
        super(name);
    }
    public static HitValueExtractor<Double> netScoreIncrement = new HitValueExtractor<Double>("netScoreIncrement") {

        @Override
        public Double getValue(Hit hit) {
            assert hit.gameList != null;
            assert hit.gameList.size() >= 3;
            double s2 = hit.gameList.get(1).getNetScore();
            double s3 = hit.gameList.get(2).getNetScore();
            return Math.abs(s2-s3) / Math.min(s2,s3);
        }

    };

    public static HitValueExtractor<Boolean> gameWithAlertFirst = new HitValueExtractor<Boolean>("") {
        @Override
        public Boolean getValue(Hit hit) {
            GameKey key = hit.gameList.get(1).getKey();
            return key.strategy == Strategy.ALERT_3_SEC ? key.gameNumber == 2 : key.gameNumber == 3;
        }
    };

    public static HitValueExtractor<Game> gameWithAlert = new HitValueExtractor<Game>("") {
        @Override
        public Game getValue(Hit hit) {
            if (gameWithAlertFirst.getValue(hit)){
                return hit.gameList.get(1);
            }
            else return hit.gameList.get(2);
        }
    };

    public static HitValueExtractor<Game> gameWithoutAlert = new HitValueExtractor<Game>("") {
        @Override
        public Game getValue(Hit hit) {
            if (!gameWithAlertFirst.getValue(hit)){
                return hit.gameList.get(1);
            }
            else return hit.gameList.get(2);
        }
    };


}
